import React, { useEffect } from 'react';
import TextChatDialog from '../../../components/textChatDialog/TextChatDialog';
import useProgramState from "../models/programState";
import config from '../../../config/config';

const ProgramPage = (props) => {

    const {
        loading, setLoading,
        textChatMessages, setTextChatMessages,
        focusBlurFlag, setFocusBlurFlag,
        completeStatus, setCompleteStatus,
        selectedPattern, setSelectedPattern,
        workflowGraph,
        onSendChat, loadWorkflowGraph
    } = useProgramState();

    useEffect(() => {
        loadWorkflowGraph();
    }, []);

    const codeTutorialOptions = config.code_tutorials.map(item => {
        let optionObj = new Object();
        optionObj.label = item.name;
        optionObj.value = item.key;
        optionObj.disabled = item.disabled;
        return optionObj;
    });

    const textChatDialogProps = {
        loading,
        libraryVisible: false,
        pageSource: "program",
        textChatMessages,
        setTextChatMessages,
        selectedPattern,
        focusBlurFlag,
        completeStatus,
        workflowGraph,
        patternOptions: codeTutorialOptions,
        documentOptions: null,
        selectDocument: null,
        selectPattern: setSelectedPattern,
        focusBlurTextArea: setFocusBlurFlag,
        onSendChat: (values, query) => onSendChat(values, query)
    }

    return (
        <div style={{ width: "100%", height: "100%" }}>
            <TextChatDialog { ...textChatDialogProps } />
        </div>
    );
}

export default ProgramPage;
